Imports System.Data

Partial Class pages_Customers_default : Inherits CPage

#region "Querystring (Filters)"
    Public ReadOnly Property Search As String
        Get
            Return CWeb.RequestStr("search")
        End Get
    End Property
    Public ReadOnly Property Paying As Boolean
        Get
            Return CWeb.RequestBool("paying", True)
        End Get
    End Property
#End Region

#Region "Members"
    Private m_customers As CCustomerList
#End Region

#Region "Data"
    Public ReadOnly Property [Customers]() As CCustomerList
        Get
            If IsNothing(m_customers) Then
                m_customers = New CCustomer().SelectSearch(ctrlCustomers.PagingInfo, txtSearch.Text, Paying) 'Sql-based Paging
                m_customers.PreloadOrders()
            End If
            Return m_customers
        End Get
    End Property
    Public Function CustomersAsDataset() As System.Data.DataSet
        Return New CCustomer().SelectSearch_Dataset(txtSearch.Text, Paying)
    End Function
#End Region

#Region "Event Handlers - Page "
    Protected Overrides Sub PageInit()
        'Populate Dropdowns
        
    
        'Search state (from querystring)
        txtSearch.Text = Me.Search
        chkPaying.Checked = Paying

        'Display Results
        ctrlCustomers.Display(Me.Customers, Search, Paying)

        'Client-side
        Me.Form.DefaultFocus  = txtSearch.ClientID
        Me.Form.DefaultButton = btnSearch.UniqueID  'CTextbox.OnReturnPress(txtSearch, btnSearch)
    End Sub
#End Region

#Region "Event Handlers - Form"
    Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click, chkPaying.CheckedChanged
        Response.Redirect(CSitemap.Customers(txtSearch.Text, chkPaying.Checked))
    End Sub
#End Region

#Region "Event Handlers - UserControl"
    Private Sub ctrl_ExportClick() Handles ctrlCustomers.ExportClick
        CDataSrc.ExportToCsv(CustomersAsDataSet, Response, "Customers.csv")
    End Sub
    Private Sub ctrl_ResortClick(ByVal sortBy As String, ByVal descending As Boolean, ByVal pageNumber As Integer) Handles ctrlCustomers.ResortClick
        Response.Redirect(CSitemap.Customers(txtSearch.Text, chkPaying.Checked, New CPagingInfo(0, pageNumber - 1, sortBy, descending)))
    End Sub
#End Region

End Class
